﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_TourCustomization_ctrTourCustomization : System.Web.UI.UserControl
{
    int nCurrent = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLabelLanguage();
            BindDataDDLWhere();
            BindWelcome();
            ValidateControl();
            GetData();
            BindDataToCustomerCountryDropdown();
            BindDataToPaymentDropdown();
            BindDataToPortOfArrivalDropdown();
            BindDataToTourDurationDropdown();
            BindDataToDay1();
            BindDataToMonth1();
            BindDataToYear1();
            BindCountryVN();
            BindCountry();
        }
    }
    #region Common
    protected void GetData()
    {
        TypeOfTourCustomization objTypeOfTourCust = new TypeOfTourCustomization();
        DataTable dtbTypeOfTourCust = new DataTable();
        dtbTypeOfTourCust = objTypeOfTourCust.GetALL();
        rptTravelStyle.DataSource = dtbTypeOfTourCust;
        rptTravelStyle.DataBind();



        HotelOption objHotelOpt = new HotelOption();
        DataTable dtbHotelOpt = new DataTable();
        dtbHotelOpt = objHotelOpt.GetALL();
        Repeater2.DataSource = dtbHotelOpt;
        Repeater2.DataBind();

        Meal objMeal = new Meal();
        DataTable dtbMeal = new DataTable();
        dtbMeal = objMeal.GetALL();
        Repeater3.DataSource = dtbMeal;
        Repeater3.DataBind();

        RoomType objRoomType = new RoomType();
        DataTable dtbRoomType = new DataTable();
        dtbRoomType = objRoomType.GetAll();
        Repeater4.DataSource = dtbRoomType;
        Repeater4.DataBind();

        Transports objTransport = new Transports();
        DataTable dtbTransport = new DataTable();
        dtbTransport = objTransport.GetALL();
        rptTransport.DataSource = dtbTransport;
        rptTransport.DataBind();

        TourGuide objTourGuide = new TourGuide();
        DataTable dtbTourGuide = new DataTable();
        dtbTourGuide = objTourGuide.GetALL();
        rptGauide.DataSource = dtbTourGuide;
        rptGauide.DataBind();
    }

    private void BindWelcome()
    {
        StaticPages obj = new StaticPages();
        obj.LoadById(39);


        switch (nCurrent)
        {
            case 1:
                lblWelcome.Text = obj.Data.PageName1;
                ltrContent.Text = obj.Data.PageContent1;
                break;
            case 2:
                lblWelcome.Text = obj.Data.PageName2;
                ltrContent.Text = obj.Data.PageContent2;
                break;
            case 3:
                lblWelcome.Text = obj.Data.PageName3;
                ltrContent.Text = obj.Data.PageContent3;
                break;
        }

    }

    private void ValidateControl()
    {
        rfvContactEmail.ErrorMessage = MultipleLanguage.CONTACT_EMAIL_EMPTY[nCurrent - 1];
        rfvContactFullname.ErrorMessage = MessagesValidate.Setting_FULLNAME_EMPTY[nCurrent - 1];
        rfvContactPhone.ErrorMessage = MessagesValidate.BASKET_TEL_EMPTY[nCurrent - 1];
        revEmail.ErrorMessage = MessagesValidate.Setting_EMAIL_WRONG[nCurrent - 1];

        revAdult.ErrorMessage = MessagesValidate.ADULTS_NUMBER[nCurrent - 1];
        revChildren.ErrorMessage = MessagesValidate.CHILDREN_NUMBER[nCurrent - 1];
    }

    private void SetLabelLanguage()
    {
        int nCurrent = Support.GetCurrentLanguage();

        lblCustomerInforMation.Text = MultipleLanguage.LBL_CUSTOMER_INFOR[nCurrent - 1];
        lblTripInfo.Text = MultipleLanguage.LBL_TRIP_INFOR[nCurrent - 1];
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nCurrent - 1];
        lblWhereToVisit.Text = MultipleLanguage.WHERETOVISIT[nCurrent - 1];
        lblTransport.Text = MultipleLanguage.TRANSPORTATION[nCurrent - 1];
        lblStyleInterest.Text = MultipleLanguage.TRAVELSTYLE[nCurrent - 1];
        lblTourGuide.Text = MultipleLanguage.TOURGUIDE[nCurrent - 1];
        lblAccommodation.Text = MultipleLanguage.ACCOMMODATION[nCurrent - 1];
        lblMeal.Text = MultipleLanguage.LBL_MEAL[nCurrent - 1];
        lblAdult.Text = MultipleLanguage.LBLADULT[nCurrent - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nCurrent - 1];

        lblCity.Text = MultipleLanguage.LBL_CITY[nCurrent - 1];
        lblFax.Text = MultipleLanguage.LBL_FAX[nCurrent - 1];
        lblExpectedDepDate.Text = MultipleLanguage.LBL_EXPECTEDDEPDATE[nCurrent - 1];
        lblPortOfArrival.Text = MultipleLanguage.LBL_PORTOFARRIVAL[nCurrent - 1];
        lblVisitationSuggestion.Text = MultipleLanguage.LBL_VISITATIONSUGGESTION[nCurrent - 1];
        lblTourCategorySuggestion.Text = MultipleLanguage.LBL_TOURCATSUGGESTION[nCurrent - 1];
        lblGuideSuggestion.Text = MultipleLanguage.LBL_TOURGUIDESUGGESTION[nCurrent - 1];
     

        lblContactEmail.Text = MultipleLanguage.EMAIL[nCurrent - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nCurrent - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nCurrent - 1];

        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nCurrent - 1];
        lblAdult.Text = MultipleLanguage.LBLADULT[nCurrent - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nCurrent - 1];
        lblContactEmail.Text = MultipleLanguage.EMAIL[nCurrent - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nCurrent - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nCurrent - 1];
        lblDuration.Text = MultipleLanguage.LBL_DURATION[nCurrent - 1];

        lblPortOfArrival.Text = MultipleLanguage.PORTOFARRIVAL[nCurrent - 1];
        lblNationality.Text = MultipleLanguage.LBL_NATIONLITY[nCurrent - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_YOURMESSAGE[nCurrent - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nCurrent - 1];
        lblExpectedDepDate.Text = MultipleLanguage.LBL_STARTDATEBOOKING[nCurrent - 1];
        lblCustomizationHotelOption.Text = MultipleLanguage.LBL_HOTELOPTION[nCurrent - 1];
        lblCustomizationRoomType.Text = MultipleLanguage.LBL_ROOMTYPE[nCurrent - 1];
        lblEverHeard.Text = MultipleLanguage.LBL_EVERHEARD[nCurrent - 1];
    }

    private void reSetLable()
    {
        txtAdult.Text = "";
        txtChild.Text = "";
        txtCity.Text = "";
        txtContactAddress.Text = "";
        txtContactEmail.Text = "";
        txtContactFullname.Text = "";
        txtContactPhone.Text = "";
        txtFax.Text = "";
        txtGuideSuggestion.Text = "";
        txtOtherRequest.Text = "";
        txtTourCategorySuggestion.Text = "";
        txtVisitationSuggestion.Text = "";
    }
    #endregion

    #region Custommer Information
    private void BindDataToCustomerCountryDropdown()
    {
        DataTable dtbCustomerCountry = new DataTable();
        CustomerCountry objCustomerCountry = new CustomerCountry();
        dtbCustomerCountry = objCustomerCountry.GetALL();

        ddlNationality.DataSource = dtbCustomerCountry;
        ddlNationality.DataValueField = "CountryID";
        switch (nCurrent)
        {
            case 1:
                ddlNationality.DataTextField = "CountryName1";
                break;
            case 2:
                ddlNationality.DataTextField = "CountryName2";
                break;
            case 3:
                ddlNationality.DataTextField = "CountryName3";
                break;
        }
        ddlNationality.DataBind();
        Utl.SetNonSelectToControl(ddlNationality, MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1]);
    }


    #endregion

    #region Trip Information
    private void BindDataToPortOfArrivalDropdown()
    {
        DataTable dtbPortOfArrival = new DataTable();
        PortOfArrival objPortOfArrival = new PortOfArrival();
        dtbPortOfArrival = objPortOfArrival.GetALL();

        ddlPortOfArr.DataSource = dtbPortOfArrival;
        ddlPortOfArr.DataValueField = "PortOfArrivalID";
        switch (nCurrent)
        {
            case 1:
                ddlPortOfArr.DataTextField = "PortOfArrivalName1";
                break;
            case 2:
                ddlPortOfArr.DataTextField = "PortOfArrivalName2";
                break;
            case 3:
                ddlPortOfArr.DataTextField = "PortOfArrivalName3";
                break;
        }
        ddlPortOfArr.DataBind();
        Utl.SetNonSelectToControl(ddlPortOfArr, MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1]);
    }

    private void BindDataToTourDurationDropdown()
    {
        DataTable dtbTourDuration = new DataTable();
        TourDuration objTourDuration = new TourDuration();
        dtbTourDuration = objTourDuration.GetALL();

        ddlDuration.DataSource = dtbTourDuration;
        ddlDuration.DataValueField = "DurationID";
        switch (nCurrent)
        {
            case 1:
                ddlDuration.DataTextField = "DurationDescription1";
                break;
            case 2:
                ddlDuration.DataTextField = "DurationDescription2";
                break;
            case 3:
                ddlDuration.DataTextField = "DurationDescription3";
                break;
        }
        ddlDuration.DataBind();
        Utl.SetNonSelectToControl(ddlDuration, MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1]);
    }

    private void BindDataDDLWhere()
    {
        ListItem item1;
        item1 = new ListItem("Internet", "1", true);
        ddlWhere.Items.Add(item1);

        ListItem item2;
        item2 = new ListItem("Friends", "2", true);
        ddlWhere.Items.Add(item2);

        ListItem item3;
        item3 = new ListItem("Magazine", "3", true);
        ddlWhere.Items.Add(item3);

        ListItem item4;
        item4 = new ListItem("Others", "4", true);
        ddlWhere.Items.Add(item4);
    }

    private void BindDataToDay1()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlDay1.Items.Add(item);
        }
    }

    private void BindDataToMonth1()
    {
        ListItem item1;
        item1 = new ListItem("Jan", "01", true);
        ddlMonth1.Items.Add(item1);

        ListItem item2;
        item2 = new ListItem("Feb", "02", true);
        ddlMonth1.Items.Add(item2);

        ListItem item3;
        item3 = new ListItem("Mar", "03", true);
        ddlMonth1.Items.Add(item3);

        ListItem item4;
        item4 = new ListItem("Apr", "04", true);
        ddlMonth1.Items.Add(item4);

        ListItem item5;
        item5 = new ListItem("May", "05", true);
        ddlMonth1.Items.Add(item5);

        ListItem item6;
        item6 = new ListItem("Jun", "06", true);
        ddlMonth1.Items.Add(item6);

        ListItem item7;
        item7 = new ListItem("Jul", "07", true);
        ddlMonth1.Items.Add(item7);

        ListItem item8;
        item8 = new ListItem("Aug", "08", true);
        ddlMonth1.Items.Add(item8);

        ListItem item9;
        item9 = new ListItem("Sep", "09", true);
        ddlMonth1.Items.Add(item9);

        ListItem item10;
        item10 = new ListItem("Oct", "10", true);
        ddlMonth1.Items.Add(item10);

        ListItem item11;
        item11 = new ListItem("Nov", "11", true);
        ddlMonth1.Items.Add(item11);

        ListItem item12;
        item12 = new ListItem("Dec", "12", true);
        ddlMonth1.Items.Add(item12);
    }

    private void BindDataToYear1()
    {
        for (int i = 2011; i < 2015; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlYear1.Items.Add(item);
        }
    }
    #endregion

    #region Where to visit
    private void BindCountryVN()
    {
        int nID = Config.COUNTRY_DEFAULT;
        Country objCountry = new Country();
        objCountry.LoadById(nID);
        lblCountry.Text = ConvertData.ConvertToString(objCountry.Data.CountryName2);

        Region objRegion = new Region();
        DataTable dtbRegion = new DataTable();
        dtbRegion = objRegion.SearchByCountry(nID);
        rptRegion.DataSource = dtbRegion;
        rptRegion.DataBind();
    }
    protected void rptRegion_ItemDataBoundVN(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblRegion = (Label)e.Item.FindControl("lblRegion");
            Repeater rptCity = (Repeater)e.Item.FindControl("rptCity");
            switch (nCurrent)
            {
                case 1:
                    lblRegion.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "RegionName1"));
                    break;
                case 2:
                    lblRegion.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "RegionName2"));
                    break;
                case 3:
                    lblRegion.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "RegionName3"));
                    break;
            }
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "RegionID"));

            City objCity = new City();
            DataTable dtbCity = new DataTable();
            dtbCity = objCity.SearchByRegion(nID);
            rptCity.DataSource = dtbCity;
            rptCity.DataBind();
        }
    }
    protected void rptCity_ItemDataBoundVN(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CityID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName3"));
                    break;
            }
        }
    }

    private void BindCountry()
    {
        Country objCustomerCountry = new Country();
        DataTable dtbCustomerCountry = new DataTable();
        dtbCustomerCountry = objCustomerCountry.GetALL();
        rptCountry.DataSource = dtbCustomerCountry;
        rptCountry.DataBind();
    }
    protected void rptCountry_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CountryID"));
            if (nID != Config.COUNTRY_DEFAULT)
            {
                Label lblCountry = (Label)e.Item.FindControl("lblCountry");
                Repeater rptCity = (Repeater)e.Item.FindControl("rptCity");
                lblCountry.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CountryName2"));

                City objCity = new City();
                DataTable dtbCity = new DataTable();
                dtbCity = objCity.GetCityByCountryID(nID);
                rptCity.DataSource = dtbCity;
                rptCity.DataBind();
            }
        }
    }
    protected void rptCity_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CityID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName3"));
                    break;
            }
        }
    }
    #endregion

    #region Transportation
    private int SetDataToCustTranport(int TourCustID)
    {
        int nresult = 1;

        int nCount = rptTransport.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)rptTransport.Items[i - 1].FindControl("chk");
            Label lblID = (Label)rptTransport.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                CustomizationTransport objCustomizationTransport = new CustomizationTransport();
                objCustomizationTransport.Data.TourCustomizationID = TourCustID;
                objCustomizationTransport.Data.TransportID = nID;
                nresult = objCustomizationTransport.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }

    protected void rptTransport_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "TransportID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            //CustomizationTransport

            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName3"));
                    break;
            }
        }
    }
    #endregion

    #region Travel Style

    protected void rptTravelStyle_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            //CustomizationCategory
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomizationlID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization3"));
                    break;
            }
        }
    }
    #endregion

    #region Meal
    private int SetDataToCustMeal(int TourCustID)
    {
        int nresult = 1;

        int nCount = Repeater3.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)Repeater3.Items[i - 1].FindControl("chk");
            Label lblID = (Label)Repeater3.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                CustomizationMeal objCustomizationMeal = new CustomizationMeal();
                objCustomizationMeal.Data.TourCustomizationID = TourCustID;
                objCustomizationMeal.Data.MealID = nID;
                nresult = objCustomizationMeal.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }

    protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "MealID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            //CustomizationMeal

            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name3"));
                    break;
            }
        }
    }

    #endregion

#region  Accommodation 
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "HotelOptionID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            //CustomizationHotelOption

            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title3"));
                    break;
            }
        }
    }

    protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            CheckBox chk = (CheckBox)e.Item.FindControl("chk");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "RoomType"));
            lblID.Text = ConvertData.ConvertToString(nID);
            //CustomizationRoomType
            switch (nCurrent)
            {
                case 1:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));
                    break;
                case 2:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));
                    break;
                case 3:
                    chk.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3"));
                    break;
            }
        }
    }

#endregion

    #region Guide
    protected void rptGauide_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            RadioButton rdo = (RadioButton)e.Item.FindControl("rdo");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "TouristGuideID"));
            lblID.Text = ConvertData.ConvertToString(nID);
            //CustomizationTransport

            switch (nCurrent)
            {
                case 1:
                    rdo.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TouristGuideName1"));
                    break;
                case 2:
                    rdo.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TouristGuideName2"));
                    break;
                case 3:
                    rdo.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TouristGuideName3"));
                    break;
            }
        }
    }
    #endregion

    #region Payment
    private void BindDataToPaymentDropdown()
    {
        DataTable dtbPayment = new DataTable();
        Payment objPayment = new Payment();
        dtbPayment = objPayment.GetAll();

        ddlPayment.DataSource = dtbPayment;
        ddlPayment.DataValueField = "PaymentID";
        ddlPayment.DataTextField = "Description";
        ddlPayment.DataBind();
        Utl.SetNonSelectToControl(ddlPayment, MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrent - 1]);
    }
    #endregion

    private int SetDataToTourGuideID(int TourCustID)
    {
        int nresult = 1;

        int nCount = rptGauide.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            RadioButton chk = (RadioButton)rptGauide.Items[i - 1].FindControl("rdo");
            Label lblID = (Label)rptGauide.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                TourCustomization objTourCust = new TourCustomization();
                objTourCust.LoadById(TourCustID);
                objTourCust.Data.GuideID = nID;
                nresult = objTourCust.Update(TourCustID);
            }
        }
        return nresult;
    }
    private int SetDataToCustCat(int TourCustID)
    {
        int nresult = 1;

        int nCount = rptTravelStyle.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)rptTravelStyle.Items[i - 1].FindControl("chk");
            Label lblID = (Label)rptTravelStyle.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                CustomizationCategory objCustomizationCategory = new CustomizationCategory();
                objCustomizationCategory.Data.TourCustomizationID = TourCustID;
                objCustomizationCategory.Data.TypeOfTravelID = nID;
                nresult = objCustomizationCategory.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }
    private int SetDataToCustCityVN(int TourCustID)
    {
        int nresult = 1;
        int nRegionCount = rptRegion.Items.Count;
        for (int j = 1; j <= nRegionCount; j++)
        {
            Repeater rptCity = (Repeater)rptRegion.Items[j - 1].FindControl("rptCity");


            
            int nCount = rptCity.Items.Count;
            for (int i = 1; i <= nCount; i++)
            {
                CheckBox chk = (CheckBox)rptCity.Items[i - 1].FindControl("chk");
                Label lblID = (Label)rptCity.Items[i - 1].FindControl("lblID");
                int nID = ConvertData.ConvertToInt(lblID.Text);
                if (chk.Checked)
                {
                    CustomizationCity objCustomizationCity = new CustomizationCity();
                    objCustomizationCity.Data.TourCustomizationID = TourCustID;
                    objCustomizationCity.Data.CityID = nID;
                    nresult = objCustomizationCity.Insert();
                    if (nresult == 0)
                    {
                        return 0;
                    }
                }
            }
        }
        return nresult;
    }
    private int SetDataToCustCity(int TourCustID)
    {
        int nresult = 1;
        int nCountryCount = rptCountry.Items.Count;
        for (int j = 1; j <= nCountryCount; j++)
        {
            Repeater rptCity = (Repeater)rptCountry.Items[j - 1].FindControl("rptCity");



            int nCount = rptCity.Items.Count;
            for (int i = 1; i <= nCount; i++)
            {
                CheckBox chk = (CheckBox)rptCity.Items[i - 1].FindControl("chk");
                Label lblID = (Label)rptCity.Items[i - 1].FindControl("lblID");
                int nID = ConvertData.ConvertToInt(lblID.Text);
                if (chk.Checked)
                {
                    CustomizationCity objCustomizationCity = new CustomizationCity();
                    objCustomizationCity.Data.TourCustomizationID = TourCustID;
                    objCustomizationCity.Data.CityID = nID;
                    nresult = objCustomizationCity.Insert();
                    if (nresult == 0)
                    {
                        return 0;
                    }
                }
            }
        }
        return nresult;
    }
    private int SetDataToCustHtOpt(int TourCustID)
    {
        int nresult = 1;
        int nCount = Repeater2.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)Repeater2.Items[i - 1].FindControl("chk");
            Label lblID = (Label)Repeater2.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                CustomizationHotelOption objCustomizationHotelOption = new CustomizationHotelOption();
                objCustomizationHotelOption.Data.TourCustomizationID = TourCustID;
                objCustomizationHotelOption.Data.HotelOptionID = nID;
                nresult = objCustomizationHotelOption.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }
    private int SetDataToRmType(int TourCustID)
    {
        int nresult = 1;

        int nCount = Repeater4.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)Repeater4.Items[i - 1].FindControl("chk");
            Label lblID = (Label)Repeater4.Items[i - 1].FindControl("lblID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                CustomizationRoomType objCustomizationRoomType = new CustomizationRoomType();
                objCustomizationRoomType.Data.TourCustomizationID = TourCustID;
                objCustomizationRoomType.Data.RoomTypeID = nID;
                nresult = objCustomizationRoomType.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }
    protected eTourCustomization setData()
    {
        eTourCustomization eTourCust = new eTourCustomization();
        eTourCust.Address = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactAddress.Text));
        eTourCust.Adults = ConvertData.ConvertToInt(txtAdult.Text);
        eTourCust.BookingDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);
        eTourCust.Children = ConvertData.ConvertToInt(txtChild.Text);
        eTourCust.CityName = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtCity.Text));
        eTourCust.Email = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactEmail.Text));
        eTourCust.ExpectedDepartureDate = ConvertData.ConvertDateStringToInt(ddlDay1.Text + "/" + ddlMonth1.SelectedValue + "/" + ddlYear1.SelectedValue);
        eTourCust.Fax = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFax.Text));
        eTourCust.FullName = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactFullname.Text));
        eTourCust.GuideSuggestion = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtGuideSuggestion.Text));
        eTourCust.Status = 0;
        eTourCust.Telephone = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactPhone.Text));
        eTourCust.TourCategorySuggestion = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtTourCategorySuggestion.Text));
        eTourCust.VisitationSuggestion = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtVisitationSuggestion.Text));
        eTourCust.OtherRequest = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtOtherRequest.Text));
        eTourCust.EverHeard = ConvertData.ConvertToInt(ddlWhere.SelectedValue);
        eTourCust.PortOfArrivalID = ConvertData.ConvertToInt(ddlPortOfArr.SelectedValue);
        eTourCust.PaymentID = ConvertData.ConvertToInt(ddlPayment.SelectedValue);
        eTourCust.DurationID = ConvertData.ConvertToInt(ddlDuration.SelectedValue);
        eTourCust.CountryID = ConvertData.ConvertToInt(ddlNationality.SelectedValue);
        return eTourCust;
    }

    #region Click Events
   
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }

    #endregion
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            TourCustomization objTourCustomization = new TourCustomization();
            objTourCustomization.Data = this.setData();
            int nID = objTourCustomization.Insert();
            int nID0 = 0, nID1 = 0, nID2 = 0, nID22 =0, nID3 = 0, nID4 = 0, nID5 = 0, nID6 = 0;
            if (nID > 0)
            {
                nID0 = SetDataToTourGuideID(nID);
                nID1 = SetDataToCustCat(nID);
                nID2 = SetDataToCustCity(nID);
                nID22 = SetDataToCustCityVN(nID);
                nID3 = SetDataToCustHtOpt(nID);
                nID4 = SetDataToCustMeal(nID);
                nID5 = SetDataToRmType(nID);
                nID6 = SetDataToCustTranport(nID);
            }
            if (nID0 * nID * nID1 * nID2 * nID22 * nID3 * nID4 * nID5 * nID6 != 0)
            {
                reSetLable();
                MessAlert1.ShowMessage(1, MessagesAlert.BOOKTOUR_SUCCESSFUL[nCurrent - 1]);
            }
            else
            {
                objTourCustomization.DeleteById(nID);
                MessAlert1.ShowMessage(1, MessagesAlert.UPDATE_UNSUCCESSFUL[nCurrent - 1]);
            }
        }
        catch
        {
            MessAlert1.ShowMessage(1, MessagesAlert.UPDATE_UNSUCCESSFUL[nCurrent - 1]);
        }
        
    }
}